<?php
/**
 * API接口管理
 * @author wubaiqing<wubaiqing@vip.qq.com>
 * @copyright Copyright (c) 2013 今天值得买
 * @since 1.5
 */
class Zhe800Controller extends Controller
{
    /**
     * 访问权限
     */
    public function accessRules()
    {
        return array();
    }

    /**
     * 加入黑名单
     * @param integer $tbId  淘宝ID
     * @param string  $title 淘宝标题
     */
    public function actionDelete($goodsId)
    {
        $goods = Goods::model()->findByPk($goodsId);
        $goods->status = 2;
        $goods->start_time = date('Y-m-d H:i:s', $goods->start_time);
        $goods->end_time = date('Y-m-d H:i:s', $goods->end_time);
        echo $goods->save();
    }


    /**
     * 修改折800商品
     */
    public function actionUpdateZhe800()
    {
        $goodsId = Yii::app()->request->getPost('goodsId');
        // 获取折800商品
        $goods = Goods::model()->findByPk($goodsId);
        $goods->attributes = $_POST;
        $goods->relation_website = 6;
        if (Yii::app()->user->id == null) {
            $this->returnData(5, '用户ID获取失败，请重新登录');
        }
        $goods->user_id = User::getUserName(Yii::app()->user->id);
        if ($goods->save()) {
            @file_get_contents('http://www.40zhe.com/api/getpushgoods/goodsId/'.$model->id.'.html');
            $this->returnData(1, '保存成功');
        } else {
            $this->returnData(4, '保存失败, 联系开发人员!');
        }
    }

    /**
     * 这800实时抓取
     */
    public function actionAdmin()
    {
        // 当前页数
        $cateId = Yii::app()->request->getQuery('cat_id', 1);

        $startTime = strtotime(date('Y-m-d'));
        $endTime = strtotime('+1 day');

        $goods = Goods::model()->findAll(array(
            'condition' => 't.start_time >=:start_time And t.start_time <:end_time And cat_id=:cat_id And status=:status And created_at=updated_at And is_zhe800=:is_zhe800',
            'params' => array(':start_time' => $startTime, ':end_time' => $endTime, ':cat_id' => $cateId, ':status' => 1, ':is_zhe800' => 1)
        ));

        $this->render('admin', array(
            'model' => $goods,
            'cateId' => $cateId,
        ));
    }
}
